package com.cn;

import com.cn.entity.FunLog;
import org.ehcache.PersistentCacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.EntryUnit;
import org.ehcache.config.units.MemoryUnit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;

import javax.cache.CacheManager;

/**
 * Created by chenyuncong on 2018/7/31.
 */
@SpringBootApplication
@EnableCaching
public class Cache3Application {

    @Bean
    public PersistentCacheManager persistentCacheManager(){
        PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
                .with(CacheManagerBuilder.persistence("D:\\ehcache2"))  //传入磁盘持久化的地址
                .withCache("persistent-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, FunLog.class,
                        ResourcePoolsBuilder.newResourcePoolsBuilder()
                                .heap(1, EntryUnit.ENTRIES)
                                .disk(1024, MemoryUnit.MB, true)) //定义一个资源的磁盘池
                ).build(true);
        return  persistentCacheManager;
    }

    public static void main(String[] args) {
        SpringApplication.run(Cache3Application.class, args);
    }
}
